#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 2e5 + 10;
typedef long long ll;
ll n;
ll a[N];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    ll sum = 0;
    ll ret = -1e5;
    for (int i = 1; i <= n; i++)
    {
        sum += a[i];
        ret = max(ret, sum);
        if (sum < 0)
        {
            sum = 0;
        }
    }
    cout << ret << endl;
    return 0;
}